package com.wechat.controller;

import com.wechat.annotation.GlobalInterceptor;
import com.wechat.entity.dto.LoginFormDTO;
import com.wechat.entity.dto.RegisterFormDTO;
import com.wechat.entity.vo.ResponseVO;
import com.wechat.redis.RedisComponent;
import com.wechat.service.UserLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/account")
@Validated//封装验证
@Slf4j
public class AccountController extends ABaseController {
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private RedisComponent redisComponent;

    /**
     * 验证码校验，使用图形验证码方式防止而已请求和自动化攻击
     * @return
     */
    @RequestMapping("/checkCode")
    public ResponseVO checkCode(){
        //使用图形验证码
        ResponseVO responseVO = userLoginService.checkCode();
        return getSuccessResponseVO(responseVO.getData());
    }

    /**
     * 注册
     * @return
     */
    @RequestMapping("/register")
    public ResponseVO register(RegisterFormDTO registerFormDTO){
        return userLoginService.register(registerFormDTO);
    }

    /**
     * 登录
     */
    @RequestMapping("/login")
    public ResponseVO login(LoginFormDTO loginFormDTO){
        return userLoginService.login(loginFormDTO);
    }

    /**
     * 获取系统设置
     */
    @RequestMapping("/getSysSetting")
    @GlobalInterceptor
    public ResponseVO getSysSetting(){
        return getSuccessResponseVO(redisComponent.getSysSetting());
    }




}